<?php

/**
 * @author christian
 * @copyright 2011
 */

Class CDrawingFillTable
{
   
    
    public static $instance;
    
    function __construct()
    {
      
        
    }
    function  DrawHead($action,$name,$method,$NAME){echo "<div id='register-box'>\n";echo "<form action='$action' method='$method' name='$name'>\n";echo "<h2>$NAME</h2>\n";}
    function  DrawFoot(){
        echo "</form>";
        echo "</div>";}
        
    function  DrawTextFillBox($items, $maintable, $idTour)
    {
            
        ?>
               <p>
               <?php 
           
               
        $query="select ";
        foreach($items as $campo => $valor){$query=$query.$campo." ,";}
        $query= substr($query,0,strlen($query)-1);
        $query=$query." from " .$maintable. " where idTour=". $idTour;
         
        //echo $query;
        $table3=CModelo::getInstance()->getData($query);
      // var_dump($table3);        
       
       
        foreach($table3 as $row =>$colum)
        {
        $tablek=$colum;$k=0;$j=0;
        foreach($tablek as $campo=>$valor)
        {
           foreach($items as $field => $name){
                $items_table[$k]=$name;   
                $k=$k+1;
        }
             
            $select="<label>". $items_table[$j];
            $select = $select."<input type='text' name='$campo' class='general-textarea' value='".$tablek[$campo]."'>";
            echo $select."</label>";
            $j=$j+1;
        }     
        }          
               ?>
               
               </p> 
            
        <?php
        
    }
    
    function DrawButton($nombre,$url){
//        echo "<form action='Cbienvenida.php' method='post'> <input type='button' name='BYLAWS' value='BYLAWS'></form>";
 //      echo "<form action='http://www.the-packrat.com/bylaws.html' method='post'> <input type='link' name='BYLAWS' value='BYLAWS' target='framename'></form>";
        //echo "<form action='http://www.the-packrat.com/bylaws.html' method='get' target='framename'><input type='button' value='BYLAWS'></form>";
        

        echo "<input type=button onClick=\"parent.location='$url'\" value='Revisar itinerario'><br/>";
        }
        
        
    function DrawSelect($maintable, $table,$campos,$NAME, $idOpe)//especificar los campos que deben de aparecer 
    {
        $query="select " ;
        foreach($campos as $campo => $valor){$query=$query.$valor.",";}
        $query= substr($query,0,strlen($query)-1);
         $query=$query." from ".$table;      

        $table2=CModelo::getInstance()->getData($query);
        
        
                $query2= "select CITY_idCit from ".$maintable." where idOpe= ". $idOpe;
                $table3=CModelo::getInstance()->getData($query2);
                var_dump($table3);
        
     foreach($table3 as $fila=>$columna)
     {
        $tabla4=$columna;
        foreach($tabla4 as $field=>$value)
        {
            $identificador=$value;
        }
     }
     echo $value;
        ?>
        
        
       
        
        <label><?php echo $NAME;?>
        <select name="type" class="input_pulldown">
        <?php
        foreach($table2 as $row =>$colum)
        {
        $tabla=$colum;
        $select="";
        $i=0;
        foreach($tabla as $campo=>$valor)
        {
            if($value==$valor){
                $select=$select."<option selected value=".$columna."> ";
            }
            //if($i>0){$select=$select."<option value=".$tabla[$campo]."> ";}
            elseif ($i<=0){$select=$select."<option value=".$valor."> ";}
            //$select=$select.$tabla[$campo].",";$i=$i+1;
            else{$select=$select.$tabla[$campo].",";}
            $i=$i+1;
        }
        echo $select."</option>\n";
        //echo "<option value=".$tabla['idOfi'].">".$tabla['DirOfi']."</option>\n";    
        }
        ?>
        </select>       
        </label>
        
    
    <?php
    }
    function DrawRadioButton($items,$name)
    {
      
      echo "<p >";
      
      foreach($items as $id => $valor)
                    {
                        echo "<label>".$id."<input type='radio' class=\"input-radio\" name='$name' value='$valor'>"."</label>\n";
                        
                    }
      
      
      echo "</p>";
      
        
        
    }
    
    function DrawSubmmit($nombre){echo "<input class='submit_button' type='submit' name=$nombre value='$nombre'>";}
    
    public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new CDrawingFillTable();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	
    
    
}

?>